import { defineStore } from 'pinia';

interface LoginUser {
  userId: string;
  username: string;
  email: string;
  avatar: string;
  institution: string;
  roles: Array<string>;
}

export const useUserStore = defineStore('users', {
  state: () => {
    return {
      loginUser: {
        userId: '',
        username: '',
        email: '',
        avatar: '',
        institution: '',
        roles: [],
      } as LoginUser,
      token: '',
    };
  },
  actions: {
    setLoginUser(loginUser: LoginUser) {
      this.loginUser = loginUser;
    },
    setToken(accessToken: string) {
      this.token = accessToken;
    },
    initUser() {
      this.loginUser = {
        userId: '',
        username: '',
        email: '',
        institution: '',
        avatar: '',
        roles: [],
      } as LoginUser;
      this.token = '';
    },
  },
});
